﻿using MyHospital.BLL;
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace MyHospital.web
{
    public partial class ManageDoctor : System.Web.UI.Page
    {
        Doctor doctor = new Doctor();
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void deleteDoctor_Click(object sender, EventArgs e)
        {
            if (Request.Form["myRadio"] == null)
            {
                lblMassage.Text = "没有选中项";
                jsLiteral.Text = "";
            }
            else
            {
                string value;
                value = Request.Form["myRadio"].ToString();
                jsLiteral.Text = "setNowRadio('" + value + "');";
                doctor.deleteDoctor(GridView2.Rows[Convert.ToInt16(value)].Cells[0].Text);
                lblMassage.Text = GridView2.Rows[Convert.ToInt16(value)].Cells[0].Text + "号医生删除成功";
                GridView2.DataSourceID = "ldsDoctor";
                GridView2.DataBind();
            }
        }

        protected void updateDoctor1_Click(object sender, EventArgs e)
        {
            if (Request.Form["myRadio"] == null)
            {
                lblMassage.Text = "没有选中项";
                jsLiteral.Text = "";
            }
            else
            {
                lblMassage.Text = "没有选中项";
                string value;
                value = Request.Form["myRadio"].ToString();
                jsLiteral.Text = "setNowRadio('" + value + "');";
                string id = GridView2.Rows[Convert.ToInt16(value)].Cells[0].Text;
                Response.Redirect("UpdateDoctor.aspx?doctorID=" + id);
            }
            lblMassage.Text = "没有选中项";
        }

        protected void insertDoctor_Click(object sender, EventArgs e)
        {
           
        }

        protected void submitInsertDocter_Click(object sender, EventArgs e)
        {
            Doctor doctor = new Doctor();
                string txtSex = "";
                if (RadioButton1.Checked) txtSex = "男";
                else if (RadioButton2.Checked) txtSex = "女";
            if (!RadioButton1.Checked && !RadioButton2.Checked) insertLable.Text = "性别未选择！";
            else if (txtInsertName == null || txtInsertAge==null||txtInsertPhone==null||txtInsertJob==null||txtInsertIntroduce==null||txtInsertImage==null||txtInsertPhone.Text.Length!=11) {
                insertLable.Text = "数据有误";
            }
            else
            {
                doctor.insertDoctor(txtInsertName.Text, dlsInsertDepart.SelectedValue, txtInsertAge.Text, txtSex, txtInsertPhone.Text, txtInsertJob.Text, txtInsertIntroduce.Text, txtInsertImage.Text);
                insertLable.Text = "插入成功";
            }
                lblMassage.Text = insertLable.Text;
        }
        protected void dlsDepart1_SelectedIndexChanged(object sender, EventArgs e)
        {
            
        }
        protected void SearcheDoctor(object sender, EventArgs e)
        {
            if (Page.IsPostBack)
            {
                if (doctor.isDoctorExit(txtDepartmentName.Text.Trim()) == false)//科室存在
                {
                    GridView2.DataSourceID = null;
                    GridView2.DataBind();
                    var results = doctor.GetDoctorsList(txtDepartmentName.Text);
                    GridView2.DataSource = results;
                    GridView2.DataBind();
                }
                else lblMassage.Text = "科室不存在";
            }
        }
        protected void SearchBack(object sender, EventArgs e)
        {
            GridView1.DataSourceID = "ldsDoctor";
            GridView1.DataBind();
        }

        protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
        {
            int page = GridView1.PageIndex;
            if (Session["indexDoctor"] != null && Session["pageDoctor"].ToString() == page.ToString())
            {
                GridView1.Rows[Convert.ToInt16(Session["indexDoctor"].ToString())].ForeColor = Color.Empty;
                GridView1.Rows[Convert.ToInt16(Session["indexDoctor"].ToString())].BackColor = Color.Empty;
            }
            int index = GridView1.SelectedIndex;//获得所选择的医生下标
            GridView1.Rows[Convert.ToInt16(index)].ForeColor = Color.Black;
            GridView1.Rows[Convert.ToInt16(index)].BackColor = ColorTranslator.FromHtml("#ccccd4");
            Session["indexDoctor"] = index.ToString();
            Session["pageDoctor"] = page.ToString();
        }
    }   
}